package com.luckeys.controller;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.luckeys.contants.CommonContans;
import com.luckeys.service.CityService;
import com.luckeys.vo.CityVO;

@RestController
@RequestMapping(value = "/city", method = RequestMethod.POST)
public class CityController {

	@Autowired
	private CityService cityService;


	@RequestMapping(value = "/queryPage", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryCityPage(@RequestBody CityVO city) {
		ModelMap resultMap = new ModelMap();

		resultMap.put(CommonContans.STRUTS_DATA,
				cityService.queryCityPage(city));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryIosCityPage", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryIosCityPage(@RequestBody CityVO city) {
		ModelMap resultMap = new ModelMap();
		resultMap.put(CommonContans.STRUTS_DATA,
				cityService.queryIosCityPage(city));
		resultMap
		.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryList", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryListCity(@RequestBody CityVO city) {
		ModelMap resultMap = new ModelMap();
		
		resultMap.put(CommonContans.STRUTS_DATA,cityService.queryCityList(city));
		resultMap.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryIosList", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryIosListCity(@RequestBody CityVO city) {
		ModelMap resultMap = new ModelMap();
		
		resultMap.put(CommonContans.STRUTS_BODY,cityService.queryIosCityList(city));
		resultMap.put(CommonContans.STRUTS_CODE, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}

	@RequestMapping(value = "/addCity", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap addCity(@RequestBody CityVO city) {
		ModelMap resultMap = new ModelMap();
		city.setCityUuid(UUID.randomUUID().toString());
		resultMap.put(CommonContans.STRUTS_DATA, cityService.addCity(city));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}

	@RequestMapping(value = "/deleteCity", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap deleteCity(String cityUuid) {
		ModelMap resultMap = new ModelMap();
		resultMap.put(CommonContans.STRUTS_DATA, cityService.deleteCity(cityUuid));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/queryCityById", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap queryCityById(String cityUuid) {
		ModelMap resultMap = new ModelMap();
		CityVO city = cityService.queryCityById(cityUuid);
		resultMap.put(CommonContans.STRUTS_DATA, city);
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
	
	@RequestMapping(value = "/updateCity", consumes = "application/json", produces = "application/json")
	@ResponseBody
	public ModelMap updateCity(@RequestBody CityVO city) {
		ModelMap resultMap = new ModelMap();
		resultMap.put(CommonContans.STRUTS_DATA, cityService.updateCity(city));
		resultMap
				.put(CommonContans.STRUTS_RESULT, CommonContans.STRUTS_SUCCESS);
		return resultMap;
	}
}
